package org.cfg;

import com.sojoys.artifact.build.data.base.BaseCfg;
import com.sojoys.artifact.tools.ToolMap;
import com.sojoys.artifact.tools.ToolCopy;
import com.sojoys.artifact.factory.bytebuff.IByteBuff;
import java.util.Map;
import com.alibaba.fastjson.JSONObject;
import com.sojoys.artifact.constant.DataModelKeyEnum;
/**
 * 蛋（抓娃娃）
 */
public class EggCfg extends BaseCfg<EggCfg> {

	/**
	 * 数据库表名称
	 */
	public static final String TABLE_NAME = "egg";
	/**
	 * 完整类名称
	 */
	public static final String CLASS_NAME = "org.cfg.EggCfg"; 
	/**
	 * 字段个数
	 */
	public static final int COLUMN_COUNT= 5;
	/**
	 * 数据库源字段注释
	 */
	public static final String[] SOURCE_COLUMN_REMARKS = new String[]{"","注释（名称）","名称文字ID","图标","使用收益",};
	/**
	 * 数据库源字段名字
	 */
	public static final String[] SOURCE_COLUMN_NAMES = new String[]{"id","name","nameTextId","icon","useProfit",};
	/**
	 * 拼音字段名字
	 */
	public static final String[] PINGYING_COLUMN_NAMES = new String[]{"id","name","nameTextId","icon","useProfit",};
	/**
	 * HashCode字段名字
	 */
	public static final Integer[] HASHCODE_COLUMN_NAMES = new Integer[]{3355,3373707,-732903021,3226745,-616468821,};
	/**
	 * 字段基本类型
	 */
	public static final String[] COLUMN_BASICTYPES = new String[]{"int","String","int","String","Map",};
	/**
	 * 字段引用类型
	 */
	public static final Class[] COLUMN_CLASSTYPES = new Class[]{Integer.class,String.class,Integer.class,String.class,Map.class,};
	
	/**
	 * id
	 */
	private int id;
	
	/**
	 * 注释（名称）
	 */
	private String name;
	
	/**
	 * 名称文字ID
	 */
	private int nameTextId;
	
	/**
	 * 图标
	 */
	private String icon;
	
	/**
	 * 使用收益
	 */
	private Map useProfit;
	
	
	
	public static EggCfg builder() {
		EggCfg eggCfg = new EggCfg();
		return eggCfg;
	}
	
	/**
	 * id
	 */
	public int getId() {
		return id;
	}
	
	/**
	 * 注释（名称）
	 */
	public String getName() {
		return name;
	}
	
	/**
	 * 名称文字ID
	 */
	public int getNameTextId() {
		return nameTextId;
	}
	
	/**
	 * 图标
	 */
	public String getIcon() {
		return icon;
	}
	
	/**
	 * 使用收益
	 */
	public Map getUseProfit() {
		return useProfit;
	}
	
	
	protected Object[] getColumnNames(DataModelKeyEnum e){
		switch (e) {
		case SOURCE:
			return SOURCE_COLUMN_NAMES;
		case PINGYING:
			return PINGYING_COLUMN_NAMES;
		case HASHCODE:
			return HASHCODE_COLUMN_NAMES;
		case REMARKS:
			return SOURCE_COLUMN_REMARKS;
		default:
			return PINGYING_COLUMN_NAMES;
		}
	}
	
	protected String[] getBasicTypes(){
		return COLUMN_BASICTYPES;
	}
	
	protected Class[] getClassTypes(){
		return COLUMN_CLASSTYPES;
	}
	
	protected Object[] getColumeValues(){
		Object[] values = new Object[COLUMN_COUNT];
        values[0] = this.id;
        values[1] = this.name;
        values[2] = this.nameTextId;
        values[3] = this.icon;
        values[4] = this.useProfit;
        return values;
	}
	
	protected EggCfg createColumeValues(Object[] vals) {
		this.id = (int)vals[0];
		this.name = (String)vals[1];
		this.nameTextId = (int)vals[2];
		this.icon = (String)vals[3];
		this.useProfit = (Map)vals[4];
		return this;
	}
	
	protected Map<Object, Object> toMap(Object[] keys,Map<Object, Object> map){
        map.put(keys[0], this.id);
        map.put(keys[1], this.name);
        map.put(keys[2], this.nameTextId);
        map.put(keys[3], this.icon);
        map.put(keys[4], this.useProfit);
        return map;
    }
    
    protected EggCfg createForMap(Object[] keys,Map map){
   		this.id = (int)map.get(keys[0]);
   		this.name = (String)map.get(keys[1]);
   		this.nameTextId = (int)map.get(keys[2]);
   		this.icon = (String)map.get(keys[3]);
   		this.useProfit = (Map)map.get(keys[4]);
        return this;
    }
	
	
	protected JSONObject toJSONObject(Object[] keys,JSONObject obj){
        obj.put(keys[0], this.id);
        obj.put(keys[1], this.name);
        obj.put(keys[2], this.nameTextId);
        obj.put(keys[3], this.icon);
        obj.put(keys[4], this.useProfit);
        return obj;
    }
    
    protected EggCfg createForJSONObject(Object[] keys,JSONObject obj){
	    this.id = obj.getIntValue(keys[0]);
	    this.name = obj.getString(keys[1]);
	    this.nameTextId = obj.getIntValue(keys[2]);
	    this.icon = obj.getString(keys[3]);
		this.useProfit = obj.getObject(keys[4],Map.class);
        return this;
    }
    
    protected void writeBytes(IByteBuff byteBuf){
	    byteBuf.writeInt(this.id);
	    byteBuf.writeString(this.name);
	    byteBuf.writeInt(this.nameTextId);
	    byteBuf.writeString(this.icon);
	    byteBuf.writeObject(this.useProfit);
    }
	
	protected EggCfg readBytes(IByteBuff byteBuf){
	    this.id = byteBuf.readInt(null);
	    this.name = byteBuf.readString(null);
	    this.nameTextId = byteBuf.readInt(null);
	    this.icon = byteBuf.readString(null);
	    this.useProfit = (Map)byteBuf.readObject();
	    return this;
	}
	
	public EggCfg deepCopy(){
		EggCfg eggCfg = null;
		try {
			eggCfg = (EggCfg) super.clone();
		    eggCfg.useProfit = ToolCopy.copyObject(this.useProfit);
			return eggCfg;
		} catch (CloneNotSupportedException e) {
			e.printStackTrace();
		}
		return eggCfg;
	}
//自定义内容起始位置
//自定义内容结束位置
}
